package com.azt.provider.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.azt.api.pojo.PrizeRecord;
import com.azt.api.pojo.PrizeSet;
import com.azt.api.service.PrizeRecordService;
import com.azt.model.page.Pagination;
import com.azt.provider.mapper.PrizeRecordMapper;
import com.azt.provider.mapper.PrizeSetMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Service
@Transactional // 事务联动,需要关联其他数据库表
public class PrizeRecordServiceImpl implements PrizeRecordService {
	@Autowired
	private PrizeRecordMapper prizeRecordmapper;

	@Override
	public Pagination selectRecordList(int pageno, int pagesize, Map<String, String> params) {
		Page<Object> startPage = PageHelper.startPage(pageno, pagesize);
		List<Map<String, String>> recordList = prizeRecordmapper.selectRecordList(params);
		Pagination p = new Pagination(startPage, recordList);
		p.setList(recordList);
		p.setParams(params);
		return p;
	}


	@Override
	public void SaveOrUpdateRecord(PrizeRecord prizeRecord) {
		if(prizeRecord.getId()!=null){
			prizeRecordmapper.updateByPrimaryKeySelective(prizeRecord);
		}else{
			prizeRecordmapper.insertSelective(prizeRecord);
		}
		
	}

	@Override
	public List<PrizeRecord> selectRecords(Integer offset,Integer limit) {
		return prizeRecordmapper.selectRecords(offset,limit);
	}

	@Override
	public List<PrizeRecord> selectRecordByState(Integer state) {
		PrizeRecord pre=new PrizeRecord();
		pre.setState(state);
		return prizeRecordmapper.select(pre);
	}


	@Override
	public List<PrizeRecord> selectExportExcelRecord(String state) {
		return prizeRecordmapper.selectExportExcelRecord(state);
	}


	@Override
	public PrizeRecord selectPrizeRecordById(Integer prizeId) {
		return prizeRecordmapper.selectByPrimaryKey(prizeId);
	}
	
	@Override
	public void delRecordById(PrizeRecord prizeRecord){
		if(prizeRecord!=null){
			prizeRecordmapper.deleteByPrimaryKey(prizeRecord.getId());
		}
		
	}
}
